package com.chutoutian.service.impl;

import com.chutoutian.mapper.ProductMapper;
import com.chutoutian.po.Product;
import com.chutoutian.service.ProductService;
import com.chutoutian.untils.SnowflakeIdWorker;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Resource
    private ProductMapper productMapper;

    @Override
    public List<Product> findByCategory(String categoryId) {
        return productMapper.findByCategory(categoryId);
    }

    @Override
    public void add(Product product) {
        product.setId(SnowflakeIdWorker.getId());
        product.setCreateTime(new Date());
        productMapper.insert(product);

    }

    @Override
    public Product get(String id) {
        return productMapper.selectById(id);
    }

    @Override
    public void update(Product product) {
        product.setModifiedTime(new Date());
        productMapper.updateById(product);
    }

    @Override
    public void delete(String id) {
        productMapper.deleteById(id);
    }
}
